//
//  QuestionAnswerDetailHeadView.m
//  HappyMother
//
//  Created by 易东 on 2017/10/26.
//  Copyright © 2017年 东哥. All rights reserved.
//

#import "QuestionAnswerDetailHeadView.h"
#import "UIView+SDAutoLayout.h"
#import "PhotosContainerView.h"

@implementation QuestionAnswerDetailHeadView
{
    PhotosContainerView *_photosContainer;
    
    CGFloat h;
}
-(void)awakeFromNib
{
    [super awakeFromNib];
    
    //最多6张图片
    PhotosContainerView *photosContainer = [[PhotosContainerView alloc] initWithMaxItemsCount:9];
    
    _photosContainer = photosContainer;
    
    [self addSubview:photosContainer];
    
    
    self.contentlbl.sd_layout.leftSpaceToView(self,15).rightSpaceToView(self,15).topSpaceToView(_linelbl,10).autoHeightRatio(0);
    
    
    _photosContainer.sd_layout
    .leftSpaceToView(self, 15)
    .topSpaceToView(_contentlbl,15)
    .rightSpaceToView(self, 15)
    .autoHeightRatio(0);
    
    // 如果你需要限制最多显示多少行文字可以这样做
    //     [self.contentLabel setMaxNumberOfLinesToShow:4];
}
#pragma mark -设置数据
-(void)setDataDict:(NSDictionary *)dataDict
{
    _dataDict = dataDict;
    
    NSString *content = dataDict[@"content"];
    
    NSArray *imageArray = dataDict[@"image"];
    
    _contentlbl.text = content;
    
    
    UIView *bottomView = _photosContainer;
    
    
    _photosContainer.photoNamesArray = imageArray;
    
    if (imageArray.count==0) {
        
        bottomView = _contentlbl;
        _photosContainer.hidden = 1;
        
    }else{
        
        _photosContainer.hidden = 0;
        
    }
    
   
    [self setupAutoHeightWithBottomView:bottomView bottomMargin:20];
    
    h = self.height;
    
    // 如果你不能确定具体哪个view会在contentview的最底部，你可以把所有可能的view都包装在一个数组里面传过去，对应的方法为 [self setupAutoHeightWithBottomViewsArray:<#(NSArray *)#> bottomMargin:<#(CGFloat)#>]
    
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    
    NSLog(@"layoutSubviews1--------%f",self.height);
    
    if (_heightBlock&&h!=self.height) {
         h = self.height;
        _heightBlock(self.height);
    }
    
}
@end
